@extends('admin.layout')
@section('content')
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                用户管理
                <small>用户列表</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 主页</a></li>
                <li><a href="#">用户管理</a></li>
                <li class="active">列表</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">快速查看用户</h3>
                        </div>
                        <div class="form-group">
                            <form action="{{ url('/admin/user/index')}}" method="get">
                            <div class="row">
                                <div class="col-md-2">
                                   @if(session('info'))
                                    <div id="jg" class="callout callout-info">
                                    <p>{{(session('info'))}}</p>
                                  </div>
                                @endif
                                    <select name="num" class="form-control">
                                       <option
                                             @if(!empty($request['num']) && $request['num']== 2)
                                            selected="selected"
                                            @endif
                                        >2</option>
                                        <option
                                             @if(!empty($request['num']) && $request['num']== 3)
                                            selected="selected"
                                            @endif
                                        >3</option>
                                        <option
                                             @if(!empty($request['num']) && $request['num']== 5)
                                            selected="selected"
                                            @endif
                                        >5</option>
                                        <option
                                             @if(!empty($request['num']) && $request['num']== 6)
                                            selected="selected"
                                            @endif
                                        >6</option>
                                    </select>
                                </div>
                                <div class="col-md-3 col-md-offset-6">
                                     <div class="input-group">
                                    <input value="{{$request['keywords'] or ''}}" name="keywords" type="text" class="form-control">
                                    <span class="input-group-btn">
                                      <button class="btn btn-info btn-flat">查询!</button>
                                    </span>
                            </div>
                            </div>
                            </div>
                            </form>
                        </div>
                        <div class="box-body">
                            <table id="example2" class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>用户邮箱</th>
                                    <th>头像</th>
                                     <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($data as $v)
                                <tr>
                                    <td class="ids">{{$v -> id}}</td>
                                    <td class="email">{{$v -> email}}
                                    </td>
                                    <td><img width="100px" src="/uploads/yhtx/{{$v -> pic}}"></td>
                                     <td class='status'>

                                    @if($v -> status == 0)
                                        禁用
                                    @elseif($v -> status == 1)
                                        启用
                                    @endif
                                    </td>
                                     <td><a href="{{url('/admin/user/edit/')}}/{{$v -> id }}">编辑</a>  <a href="{{url('/admin/user/delete/')}}/{{$v -> id }}">删除</a></td>
                                </tr>
                                @endforeach
                            </table>
                           {!! $data -> appends($request)->render() !!}
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->


                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->
    <script type="text/javascript">
        window.onload = function()
        {
            $.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

            $('.status').on('dblclick',function(){
                var t = $(this);

                 //获取id
                var id = $(this).parent().find('.ids').html();
                //alert(id);
                $.ajax({
                    type:"POST",
                    url:"{{url('/admin/user/ajaxStatus')}}",
                    data:{id:id},
                    success:function(data)
                    {

                        if(data == 2)
                        {
                            alert('修改失败');
                        }else if(data == 0)
                        {
                            t.html('禁用');
                        }else if(data == 1)
                        {
                            t.html('开启');
                        }
                    },
                    error:function()
                    {
                        alert('异常');
                    }
            });
        });
    }
    //双击修改用户名
    $(".email").on('dblclick',function(){
         //获取id
        var id = $(this).parent().find('.ids').html();
          $.ajax({
            type:"POST",
            url:"{{url('/admin/user/ajaxEmail')}}",
            data:{id:id},
            success:function(data)
            {
                alert(data);

            },
            error:function()
            {
                alert('异常');
            }
         });
    });
    </script>
@endsection